import Mock from 'mockjs';

// 生成列表数据
Mock.mock(/\/api\/v1\/tech-insight\/list/, 'get', (options: { url: any; }) => {
  const { url } = options;
  const params = new URLSearchParams(url.split('?')[1]);
  const page = parseInt(params.get('page') || '1');
  const pageSize = parseInt(params.get('pageSize') || '20');

  return {
    code: 200,
    data: {
      total: 100,
      list: Mock.mock({
        [`list|${pageSize}`]: [{
          'insightId|+1': Mock.Random.guid(),
          'title': '@ctitle(10, 30)',
          'category': '@pick(["AI", "区块链", "云计算", "物联网"])',
          'field': '@pick(["金融", "医疗", "教育", "制造"])',
          'summary': '@cparagraph(1, 3)',
          'source': '@pick(["研究报告", "行业新闻", "专家观点"])',
          'publishTime': '@datetime',
          'author': '@cname',
          'tags|1-5': ['@ctitle(2, 4)'],
          'viewCount|100-10000': 100,
          'importance|1-5': 1
        }]
      }).list
    },
    message: 'success'
  };
});

// 获取详情
Mock.mock(/\/api\/v1\/tech-insight\/[\w-]+$/, 'get', () => {
  return {
    code: 200,
    data: Mock.mock({
      'insightId': '@guid',
      'title': '@ctitle(10, 30)',
      'category': '@pick(["AI", "区块链", "云计算", "物联网"])',
      'field': '@pick(["金融", "医疗", "教育", "制造"])',
      'content': {
        'background': '@cparagraph(3, 5)',
        'analysis': '@cparagraph(5, 8)',
        'impact': '@cparagraph(4, 6)',
        'trend': '@cparagraph(4, 6)',
        'suggestion': '@cparagraph(4, 6)'
      },
      'charts|1-3': [{
        'title': '@ctitle(5, 10)',
        'type': '@pick(["line", "bar", "pie", "scatter", "radar"])',
        'data': {
          'dimensions': ['@date', '@natural(1, 100)'],
          'source|6': [['@date', '@natural(1, 100)']]
        },
        'description': '@csentence'
      }],
      'references|3-8': [{
        'title': '@ctitle(10, 20)',
        'url': '@url',
        'type': '@pick(["paper", "patent", "news"])'
      }],
      'relatedInsights|3': [{
        'insightId': '@guid',
        'title': '@ctitle(10, 30)',
        'relevance|0-1': 0.1
      }],
      'source': '@pick(["研究报告", "行业新闻", "专家观点"])',
      'publishTime': '@datetime',
      'author': '@cname',
      'tags|1-5': ['@ctitle(2, 4)'],
      'viewCount|100-10000': 100,
      'importance|1-5': 1,
      'updateTime': '@datetime'
    }),
    message: 'success'
  };
});

// 创建洞察
Mock.mock('/api/v1/tech-insight', 'post', () => {
  return {
    code: 200,
    data: {
      insightId: Mock.Random.guid()
    },
    message: '创建成功'
  };
});

// 更新洞察
Mock.mock(/\/api\/v1\/tech-insight\/[\w-]+$/, 'put', () => {
  return {
    code: 200,
    message: '更新成功'
  };
});

// 删除洞察
Mock.mock(/\/api\/v1\/tech-insight\/[\w-]+$/, 'delete', () => {
  return {
    code: 200,
    message: '删除成功'
  };
});